package org.springperu.aop.demo.dao.jdbc;

import java.util.Date;
import java.util.List;

import javax.sql.DataSource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.support.JdbcDaoSupport;
import org.springframework.stereotype.Repository;
import org.springperu.aop.demo.dao.AuditDao;
import org.springperu.aop.demo.model.Audit;

@Repository
public class AuditDaoJdbc implements AuditDao{
	private JdbcTemplate jdbcTemplate;
	
	@Autowired
	public void setDataSource(DataSource dataSource) {
		jdbcTemplate = new JdbcTemplate(dataSource);
	}
	
	public void saveAudit(Audit audit) {
		jdbcTemplate.update("insert into audit(operation,query,user_id,audit_date) values(?,?,?,?)",
				audit.getOperation(),audit.getQuery(),audit.getUser_id(),audit.getAudit_date()
		);
	}

	public List getAllAudits() {
		return jdbcTemplate.queryForList("select audit_id, operation, query, user_id, audit_date from audit");
	}
	
	
}
